package com.ygqh.baby.model;

import com.mumu.commons.utils.StringUtils;
import com.ygqh.baby.utils.DateConvertUtils;
import org.apache.commons.collections.CollectionUtils;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author admin
 *
 */
public class DrawPrize {

	private String activityName;

	private String sourceCode;

	private Date startDate;

	private Date endDate;

	private String handler;

	private Date updateTime;

	private Integer defaultIndex;

	private LinkedList<PrizeItem> prizeItems;

	private Integer giveCount;

	private Boolean falg = true;// 前端抽中标记

	public Boolean getFalg() {
		return falg;
	}

	public void setFalg(Boolean falg) {
		this.falg = falg;
	}

	public String getBaseKey(Boolean hasTimeStamp) {
		return getBaseKey(hasTimeStamp, null);
	}

	public String getBaseKey(Boolean hasTimeStamp, String platformNo) {
		if (!hasTimeStamp) {
			return getSourceCode(platformNo);
		}
		String format = DateConvertUtils.format(new Date());
		return getSourceCode(platformNo) + "-" + format;
	}

	public Boolean isValid() {
		Date currentDate = DateConvertUtils.getDateStart(new Date());

		if ((startDate == null || currentDate.compareTo(startDate) >= 0)
				&& (endDate == null || currentDate.compareTo(endDate) <= 0)) {
			return true;
		}
		return false;
	}

	public List<Double> getRates() {
		if (!CollectionUtils.isEmpty(prizeItems)) {
			return prizeItems.stream().map(item -> item.getRate().doubleValue()).collect(Collectors.toList());
		}
		return null;
	}

	public List<Double> getRates(boolean newCustom) {
		if (!CollectionUtils.isEmpty(prizeItems)) {
			return prizeItems.stream().map(item -> item.getRate(newCustom).doubleValue()).collect(Collectors.toList());
		}
		return null;
	}

	public Integer getGiveCount() {
		return giveCount;
	}

	public void setGiveCount(Integer giveCount) {
		this.giveCount = giveCount;
	}

	public String getActivityName() {
		return activityName;
	}

	public void setActivityName(String activityName) {
		this.activityName = activityName;
	}

	public Integer getDefaultIndex() {
		return defaultIndex;
	}

	public void setDefaultIndex(Integer defaultIndex) {
		this.defaultIndex = defaultIndex;
	}

	public LinkedList<PrizeItem> getPrizeItems() {
		return prizeItems;
	}

	public void setPrizeItems(LinkedList<PrizeItem> prizeItems) {
		this.prizeItems = prizeItems;
	}

	public String getSourceCode() {
		return sourceCode;
	}

	public String getSourceCode(String platformNo) {
		if (StringUtils.isNotBlank(platformNo)) {
			return sourceCode + platformNo;
		}
		return sourceCode;
	}

	public void setSourceCode(String sourceCode) {
		this.sourceCode = sourceCode;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		if (startDate != null) {
			startDate = DateConvertUtils.getDateStart(startDate);
		}
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		if (endDate != null) {
			endDate = DateConvertUtils.getDateStart(endDate);
		}
		this.endDate = endDate;
	}

	public String getHandler() {
		return handler;
	}

	public void setHandler(String handler) {
		this.handler = handler;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Override
	public String toString() {
		return "DrawPrize{" +
				"activityName='" + activityName + '\'' +
				", sourceCode='" + sourceCode + '\'' +
				", startDate=" + startDate +
				", endDate=" + endDate +
				", handler='" + handler + '\'' +
				", updateTime=" + updateTime +
				", defaultIndex=" + defaultIndex +
				", prizeItems=" + prizeItems +
				", giveCount=" + giveCount +
				", falg=" + falg +
				'}';
	}
}
